import { Component, OnInit } from '@angular/core';
import { webSocketService } from '../shared/websocket.service';

@Component({
  selector: 'app-web-socket',
  templateUrl: './web-socket.component.html',
  styleUrls: ['./web-socket.component.css']
})
export class WebSocketComponent implements OnInit {

  constructor(private websocket:webSocketService) { }

  ngOnInit() {
    //订阅websocket返回的流数据
    this.websocket.createWebSocketObservable('ws://localhost:8085')
      .subscribe(
        data => console.log(data),
        error => console.log(error),
        () => console.log('流已经结束了')
      )
  }

  sendMessAgeToServer(message){
    this.websocket.sendMessage(message);
  }

}
